package controllers

import (
	"go_backend/models"

	"github.com/astaxie/beego"
)

/**
 *  @Title  UserAnalyzeController
 *  @author liqi 2018/12/12 11:20
 *  @Description 用户分析统计
 */

type UserAnalyzeController struct {
	beego.Controller
}

// @Title Get
// @author  liqi 2018/12/12 11:21
// @Description 用户分析
// @router /user/analyze [GET]
func (this *UserAnalyzeController) Get() {
	var errShiyin = make(chan int, 1)
	var errCps = make(chan int, 1)
	go models.AnalyzeUsers(1, errShiyin) //十音
	go models.AnalyzeUsers(2, errCps)    //cps
	if <-errShiyin == 0 && <-errCps == 0 {
		this.resJson("ok~", "")
		return
	}
	this.resJson("failed!", "")

	//this.ifGoBool(<-goerr, "出错了~", <-goerr)
}

// @Title   ifBool
// @author  liqi 2018/12/12 16:20
// @Description	judge bool , true or false
func (this *UserAnalyzeController) ifBool(bool bool, errmsg string, data interface{}) {
	if !bool {
		this.resJson(errmsg, "")
	}
	this.resJson("ok~", data)
}

// @Title resJson
// @Description global response
func (this *UserAnalyzeController) resJson(msg string, data interface{}) {
	this.Data["json"] = map[string]interface{}{"code": 200, "message": msg, "data": data}
	this.ServeJSON()
}
